# coding:utf-8
# author:frank
# date:2024/12/31
import pygame
clock = pygame.time.Clock()
pygame.init()

win_w=500
win_h=600
win = pygame.display.set_mode((win_w,win_h))
pygame.display.set_caption("自由落体")
win.fill('white')
pygame.display.flip()

y = 220
diff = 15
jumping = False
img = pygame.image.load('files/tank_right.png')
img = pygame.transform.scale(img,(50,50))
win.blit(img,(100,y))

while True:
    clock.tick(30)
    win.fill('white')
    win.blit(img,(100,y))
    if jumping:
        # 让y每次-diff,diff每次-1,物体向上移动,速度由快到慢
        # 当diff小于0时,y-负的diff等于和diff相加,物体开始向下移动,速度由慢到快
        y -= diff
        diff -= 1
        print("当前Y：",y,"当前diff:",diff)
        if y==220:
            diff = 15
            jumping = False
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_SPACE:
                jumping = True
    pygame.display.update()